import 'package:dio/dio.dart';

import '../api_code.dart';
import '../api_result.dart';

/// response拦截器
class ResponseInterceptors extends InterceptorsWrapper {
  @override
  onResponse(Response response) async {
    RequestOptions option = response.request;
    try {
      if (option.contentType != null) {
        ResultData data = new ResultData(response.data, true, ApiCode.SUCCESS);
        return data;
      }
      if (response.statusCode == 200 || response.statusCode == 201) {
        ResultData data = new ResultData(response.data, true, ApiCode.SUCCESS,
            headers: response.headers);
        return data;
      }
    } catch (e) {
      print(e.toString() + option.path);
      return new ResultData(response.data, false, response.statusCode,
          headers: response.headers);
    }
  }
}
